"""Drop User, Entity, Organization etc tables

Revision ID: bce2fbe6273b
Revises: af2ecf7ca19a
Create Date: 2025-04-11 12:38:43.626898+00:00

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision: str = 'bce2fbe6273b'
down_revision: Union[str, None] = 'af2ecf7ca19a'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('memberships')
    op.drop_table('subscriptions')
    op.drop_table('users')
    op.drop_table('organizations')
    op.drop_table('entities')
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('subscriptions',
    sa.Column('id', sa.UUID(), autoincrement=False, nullable=False),
    sa.Column('entity_id', sa.UUID(), autoincrement=False, nullable=False),
    sa.Column('plan', postgresql.ENUM('CUSTOM', 'FREE', 'PRO', 'ENTERPRISE', name='subscriptionplan'), autoincrement=False, nullable=False),
    sa.Column('status', postgresql.ENUM('ACTIVE', 'CANCELLED', 'EXPIRED', name='subscriptionstatus'), autoincrement=False, nullable=False),
    sa.Column('expires_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True),
    sa.Column('created_at', postgresql.TIMESTAMP(), server_default=sa.text('now()'), autoincrement=False, nullable=False),
    sa.Column('updated_at', postgresql.TIMESTAMP(), server_default=sa.text('now()'), autoincrement=False, nullable=False),
    sa.ForeignKeyConstraint(['entity_id'], ['entities.id'], name='subscriptions_entity_id_fkey'),
    sa.PrimaryKeyConstraint('id', name='subscriptions_pkey')
    )
    op.create_table('organizations',
    sa.Column('id', sa.UUID(), autoincrement=False, nullable=False),
    sa.ForeignKeyConstraint(['id'], ['entities.id'], name='organizations_id_fkey'),
    sa.PrimaryKeyConstraint('id', name='organizations_pkey'),
    postgresql_ignore_search_path=False
    )
    op.create_table('users',
    sa.Column('id', sa.UUID(), autoincrement=False, nullable=False),
    sa.Column('identity_provider', sa.VARCHAR(length=255), autoincrement=False, nullable=False),
    sa.Column('user_id_by_provider', sa.VARCHAR(length=255), autoincrement=False, nullable=False),
    sa.ForeignKeyConstraint(['id'], ['entities.id'], name='users_id_fkey'),
    sa.PrimaryKeyConstraint('id', name='users_pkey'),
    sa.UniqueConstraint('identity_provider', 'user_id_by_provider', name='uc_auth_provider_user'),
    postgresql_ignore_search_path=False
    )
    op.create_table('entities',
    sa.Column('id', sa.UUID(), autoincrement=False, nullable=False),
    sa.Column('type', postgresql.ENUM('ENTITY', 'USER', 'ORGANIZATION', name='entitytype'), autoincrement=False, nullable=False),
    sa.Column('name', sa.VARCHAR(length=255), autoincrement=False, nullable=False),
    sa.Column('email', sa.VARCHAR(length=255), autoincrement=False, nullable=False),
    sa.Column('profile_picture', sa.TEXT(), autoincrement=False, nullable=True),
    sa.Column('created_at', postgresql.TIMESTAMP(), server_default=sa.text('now()'), autoincrement=False, nullable=False),
    sa.Column('updated_at', postgresql.TIMESTAMP(), server_default=sa.text('now()'), autoincrement=False, nullable=False),
    sa.PrimaryKeyConstraint('id', name='entities_pkey'),
    postgresql_ignore_search_path=False
    )
    op.create_table('memberships',
    sa.Column('id', sa.UUID(), autoincrement=False, nullable=False),
    sa.Column('user_id', sa.UUID(), autoincrement=False, nullable=False),
    sa.Column('organization_id', sa.UUID(), autoincrement=False, nullable=False),
    sa.Column('role', postgresql.ENUM('ADMIN', 'MEMBER', name='organizationrole'), autoincrement=False, nullable=False),
    sa.Column('created_at', postgresql.TIMESTAMP(), server_default=sa.text('now()'), autoincrement=False, nullable=False),
    sa.Column('updated_at', postgresql.TIMESTAMP(), server_default=sa.text('now()'), autoincrement=False, nullable=False),
    sa.ForeignKeyConstraint(['organization_id'], ['organizations.id'], name='memberships_organization_id_fkey'),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], name='memberships_user_id_fkey'),
    sa.PrimaryKeyConstraint('id', name='memberships_pkey')
    )
    # ### end Alembic commands ###
